﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Baza.EF.BLL;
using Baza.EF.DAL;

namespace Pep_3014_3070_Desktop
{
    public partial class AddReservation : Form
    {
        public AddReservation()
        {
            InitializeComponent();
        }

        private void AddReservation_Load(object sender, EventArgs e)
        {
            cmbKlijent.DataSource = DAIznajmljivaciApartmani.SelectOwners();
            cmbKlijent.DisplayMember = "FirstName,LastName";

            cmbApartman.DataSource = DAIznajmljivaciApartmani.SelectAllApartments();
            cmbApartman.DisplayMember = "Title";
        }

        private void cmbKlijent_Format(object sender, ListControlConvertEventArgs e)
        {
            string lastname = ((Customers)e.ListItem).FirstName;
            string firstname = ((Customers)e.ListItem).LastName;
            e.Value = lastname + " " + firstname;
        }

        private void btnSpremi_Click(object sender, EventArgs e)
        {
            Reservations reservation = new Reservations();

            reservation.CheckIn = DateTimeCheckIn.Value;
            reservation.CheckOut = DateTimeCheckOut.Value;
            reservation.Price = Decimal.Parse(TextPrice.Text);

            Apartments apartment = (Apartments)cmbApartman.SelectedItem;
            Customers customer = (Customers)cmbKlijent.SelectedItem;

            DAIznajmljivaciApartmani.ReservationsInsert(reservation, apartment.ApartmentID, customer.CustomerID);


            MessageBox.Show(Global.GetString("reservation_succ"), "Iznajmljivači", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }
    }
}
